package com.hksj.em.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hksj.common.config.annotation.CurrentUserIdAndName;
import com.hksj.common.core.model.Rest;
import com.hksj.em.dto.create.CreateOperationRoomDTO;
import com.hksj.em.dto.delete.DeleteOperationRoomDTO;
import com.hksj.em.dto.update.UpdateOperationRoomDTO;
import com.hksj.em.entity.OperationRoom;
import com.hksj.em.enums.PageEnum;
import com.hksj.em.query.OperationRoomQuery;
import com.hksj.em.service.OperationRoomService;
import com.hksj.em.vo.LatestOperationRoomVO;
import com.hksj.em.vo.OperationRoomDataVO;
import com.hksj.em.vo.OperationRoomVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author zengke
 * @version 1.0
 * @see OperationRoomController
 * @since 2025/03/25 9:59
 */

@Api(tags = "数据同步-手术室管理")
@RequestMapping(value = "/api/operationRoom")
@RestController
public class OperationRoomController{

    @Resource
    private OperationRoomService operationRoomService;

    @ApiOperation(value = "新增手术室")
    @PostMapping(value = "/createOperationRoom")
    @CurrentUserIdAndName(id = "operatorId")
    public Rest<String> createOperationRoom(@RequestBody CreateOperationRoomDTO dto){
        String result = operationRoomService.createOperationRoom(dto);
        return Rest.ok(result);
    }

    @ApiOperation(value = "更新手术室")
    @PutMapping(value = "/updateOperationRoom")
    @CurrentUserIdAndName(id = "operatorId")
    public Rest<String> updateOperationRoom(@RequestBody UpdateOperationRoomDTO dto){
        String result = operationRoomService.updateOperationRoom(dto);
        return Rest.ok(result);
    }

    @ApiOperation(value = "删除手术室")
    @DeleteMapping(value = "/deleteOperationRoom")
    public Rest<String> deleteOperationRoom(@RequestBody DeleteOperationRoomDTO dto){
        String result = operationRoomService.deleteOperationRoom(dto);
        return Rest.ok(result);
    }

    @ApiOperation(value = "查询手术间下拉框")
    @GetMapping(value = "/listOperationRoom")
    public Rest<List<OperationRoom>> listOperationRoom(){
        List<OperationRoom> operationRoomList = operationRoomService.list();
        return Rest.ok(operationRoomList);
    }


    @ApiOperation(value = "动态查询手术室列表",response = OperationRoomVO.class)
    @PostMapping(value = "/queryOperationRoomList")
    public Rest queryOperationRoomList(@RequestBody OperationRoomQuery query){

        //判断是否分页查询
        if (Objects.equals(query.getPageStatus(), PageEnum.PAGE.getType())){

            //进行分页查询
            IPage<OperationRoomVO> page = operationRoomService.queryOperationRoomListByPaging(query);

            //返回分页结果
            return Rest.ok(page);
        } else {

            //不进行分页查询
            List<OperationRoomVO> operationRoomList = operationRoomService.queryOperationRoomList(query);

            //返回动态查询结果
            return Rest.ok(operationRoomList);
        }
    }

    @ApiOperation(value = "分页查询各手术室最新信息列表")
    @PostMapping("/queryLatestOperationRoomInfoListByPaging")
    public Rest<IPage<LatestOperationRoomVO>> queryLatestOperationRoomInfoListByPaging(@RequestBody OperationRoomQuery query){
        IPage<LatestOperationRoomVO> page = operationRoomService.queryLatestOperationRoomInfoListByPaging(query);
        return Rest.ok(page);
    }

    @ApiOperation(value = "同步手术室信息")
    @GetMapping("/syncOperationRoom")
    public Rest<String> syncOperationRoom(){
        String result = operationRoomService.syncOperationRoom();
        return Rest.ok(result);
    }

    @ApiOperation(value = "查询手术间的数据列表")
    @PostMapping("/queryOperationRoomDataList")
    public Rest<List<OperationRoomDataVO>> queryOperationRoomDataList(String roomCode){
        List<OperationRoomDataVO> operationRoomDataVOS = operationRoomService.queryOperationRoomDataList(roomCode);
        return Rest.ok(operationRoomDataVOS);
    }
}
